package com.bdqn.t382.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class RegisterController {
    private static final Logger LOGGER = LoggerFactory.getLogger(RegisterController.class);

    @RequestMapping("/register")
    protected String register(HttpServletRequest request) throws Exception {
        LOGGER.info("Spring MVC 框架搭建成功，当前请求路径:{}", request.getRequestURI());
        return "register";
    }

    // 一个控制器类中可以定义多个控制器方法
    @RequestMapping("/doRegister")
    protected ModelAndView doRegister(@RequestParam(name = "realName", required = false) String name) throws Exception {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("realName", name);
        modelAndView.setViewName("success");
        return modelAndView;
    }
}
